package lib.pay;

import lib.Dao.TokenDao;
import lib.servlet.AuthUtil;
import lib.wxpay.sdk.WXPayUtil;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//import org.apache.http.HttpRequest;


public class jssdk {
    /**
     * @param request
     * @return Map
     * @Description 微信浏览器内微信支付/公众号支付(JSAPI)
     */
    @RequestMapping(value = "/jssdk", method = RequestMethod.GET)
    @ResponseBody

    public Map orders(HttpServletRequest request) {
        try {
            JSONObject jsonObject;
            //获取jsapi权限
            TokenDao tokenDao=new TokenDao();
            String GET_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+tokenDao.gettoken()+"&type=jsapi";
            jsonObject = AuthUtil.doGetJson(GET_TICKET_URL);
            String ticket=jsonObject.getString("ticket");
            Map<String, String> payMap = new HashMap<String, String>();
            payMap.put("appId","wx291b25f289a25814");
            payMap.put("timeStamp", WXPayUtil.getCurrentTimestamp() + "");
            payMap.put("nonceStr", WXPayUtil.generateNonceStr());
            payMap.put("signType", "MD5");
            String paySign = WXPayUtil.generateSignature(payMap, "lipeiyuan12138lipeiyuan12138lipe");
            payMap.put("paySign", paySign);
            return payMap;



        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}